/******************************************************************************
* This file is part of is32p218 platform,
* Copyright (c) 2009 HangZhou InfoStrong CO.,LTD. All rights reserved.
* This software may only be used under the terms of a valid, current,
* end user license from InfoStrong.
* Nothing else gives you the right to use this software.   
*
* Name:   os_port.h
* Desc:   OS Hardware Abstract Layer Header File
* Author: Jerry
* Date:   2009-9-15
* Note:   
* History:
*
******************************************************************************/

#include "isOS.h"
#include "os_glb.h"

#ifndef __OS_PORT_H__
#define __OS_PORT_H__

#ifdef __cplusplus
extern "C" {
#endif

#define  OS_TIMER_STACK_SIZE   64
#define  OS_IDLE_STACK_SIZE    48
#define  OS_MIN_STACK_SIZE     40        //--  +20 for exit func when ver GCC > 4

#define  OS_BITS_IN_INT        32

#define  OS_ALIG                4
#define  MAKE_ALIG(a)  (((sizeof(a) + (OS_ALIG-1)) / OS_ALIG) * OS_ALIG)

#define  OS_PORT_STACK_EXPAND_AT_EXIT  16

 //--- ARM ----

    //-- Assembler functions prototypes

#ifdef __cplusplus
extern "C"  {
#endif

  void  os_switch_context_exit(void); //isOS_U32 cpsr_saved); //-- v.2.4
  void  os_switch_context(void);
  void  os_cpu_irq_isr(void);
  void  os_cpu_fiq_isr(void);

  isOS_U32   os_cpu_save_sr(void);
  void  os_cpu_restore_sr(isOS_U32 sr);
  void  os_start_exe(void);
  isOS_S32   os_chk_irq_disabled(void);
  isOS_S32   os_chk_tumb(void); //-- v.2.4
  isOS_S32   ffs_asm(isOS_U32 val);

#ifdef __cplusplus
}  /* extern "C" */
#endif

    //-- Interrupt processing   - processor specific
#define  OS_INTSAVE_DATA_INT
#define  OS_INTSAVE_DATA         isOS_S32 os_save_status_reg = 0
#define  os_disable_interrupt()  os_save_status_reg = os_cpu_save_sr()
#define  os_enable_interrupt()   os_cpu_restore_sr(os_save_status_reg)
#define  os_idisable_interrupt() ;
#define  os_ienable_interrupt()  ;


/*Implemented in specific part*/
extern isOS_U32	OS_CPU_SR_Save(void);
extern void		OS_CPU_SR_Restore(isOS_U32 cpu_sr);

#define  isOS_ENTER_CRITICAL(cpu_sr)  {cpu_sr = os_cpu_save_sr();}
#define  isOS_EXIT_CRITICAL(cpu_sr)   {os_cpu_restore_sr(cpu_sr);}


isOS_U32 * isOS_StackInit(void * task_func,void * stack_start, void * param);
   //-- Routines


//----- os_user.c ----------------------------------

#ifdef __cplusplus
}
#endif

#endif /*__OS_PORT_H__*/




